﻿using System;
using System.Collections.ObjectModel;

namespace Microsoft.Coding4Fun.TweetCraft.Twitter
{
    /// <summary>
    /// Downloads tweets and Twitter user photos in the background and raises notifications
    /// when new tweets are available.
    /// </summary>
    public interface ITwitterBackgroundService
    {
        /// <summary>
        /// Gets the latest tweets from the User timeline.
        /// </summary>
        ReadOnlyCollection<Tweet> Tweets { get; }

        /// <summary>
        /// Gets the latest replies to the user.
        /// </summary>
        ReadOnlyCollection<Tweet> Replies { get; }

        /// <summary>
        /// Gets or sets a value indicating whether Twitter is polled for new tweets periodically.
        /// </summary>
        bool PollingEnabled { get; set; }

        /// <summary>
        /// Gets or sets the <see cref="TimeSpan"/> between polling the Twitter service.
        /// </summary>
        TimeSpan PollingInterval { get; set; }
        
        /// <summary>
        /// Raised when new tweets or replies are available as part of polling Twitter.
        /// </summary>
        event EventHandler TweetsChanged;

        /// <summary>
        /// Polls the Twitter service.
        /// </summary>
        void Poll();

        /// <summary>
        /// Trigger a polling asynchronously in the background.
        /// </summary>
        /// <remarks>
        /// The <see cref="TwitterBackgroundService.PollingEnabled"/> must be set to true
        /// for polling to occur.
        /// </remarks>
        void PollAsync();
    }
}
